package com.toune.gdlocation.location

import android.animation.ValueAnimator
import android.content.Context
import android.view.View
import android.view.ViewGroup
import com.qmuiteam.qmui.util.QMUIDisplayHelper


object ViewUtil {
    /**
     * (x,y)是否在view的区域内
     *
     * @param view
     * @param x
     * @param y
     * @return
     */
    fun isTouchPointInView(view: View, x: Int, y: Int): Boolean {
        val location = IntArray(2)
        view.getLocationOnScreen(location)
        val left = location[0]
        val top = location[1]
        val right = left + view.measuredWidth
        val bottom = top + view.measuredHeight

        return y in top..bottom && x >= left && x <= right
    }


    fun animOut(context: Context, view: View) {
        val animator = ValueAnimator.ofInt(QMUIDisplayHelper.dp2px(context, 180), QMUIDisplayHelper.dp2px(context, 260))
        animator.addUpdateListener { animation ->
            val params: ViewGroup.LayoutParams = view.layoutParams
            params.height = animation.animatedValue as Int
            view.layoutParams = params
        }
        animator.duration = 400
        animator.start()
    }

    fun animIn(context: Context, view: View) {
        val animator = ValueAnimator.ofInt(QMUIDisplayHelper.dp2px(context, 260), QMUIDisplayHelper.dp2px(context, 180))
        animator.addUpdateListener { animation ->
            val params: ViewGroup.LayoutParams = view.layoutParams
            params.height = animation.animatedValue as Int
            view.layoutParams = params
        }
        animator.duration = 400
        animator.start()
    }
}